package com.xiong.proxy;

import com.xiong.proxy.Interceptor.CustomMethodInterceptor;
import net.sf.cglib.proxy.Enhancer;

public class Test {

    public static void main(String[] args) {
        // 创建目标类的实例
        TargetClass target = new TargetClass();

        // 创建CGLIB的Enhancer对象
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(TargetClass.class);
        enhancer.setCallback(new CustomMethodInterceptor());

        // 创建代理类
        TargetClass proxy = (TargetClass) enhancer.create();

        // 调用代理类的方法
        proxy.doSomething();
    }

    @org.junit.Test
    public void Test1(){
        TargetClass targetClass=CglibEngine.createObj(TargetClass.class);
        targetClass.doSomething();
    }

    static class TargetClass{

        public void doSomething(){
            System.out.println("执行了");
        }
    }
}
